package org.chenbingkang.boot.controller;

import org.chenbingkang.boot.pojo.TaskInfo;
import org.chenbingkang.boot.quartz.SchedulerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/scheduler")
public class SchedulerController {
    @Autowired
    private SchedulerService schedulerService;

    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> listJob() {
        Map<String, Object> taskInfos = schedulerService.listJob();
        return taskInfos;
    }

    /**
     {
         "jobName":"test",
         "jobGroup":"test",
         "jobClassName":"org.chenbingkang.quartz.QuartzJob",
         "params":"",
         "url":"",
         "jobDescription":"test"
         "cronExpression":"0/10 * * * * ?"
     }
     * @param info
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public void addJob(@RequestBody TaskInfo info) {
        schedulerService.addJob(info);
    }

    @RequestMapping(value = "/del", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public void delJob(String jobGroup,String jobName) {
        schedulerService.deleteJob(jobGroup,jobName);
    }
}
